package com.second.teacher.service.ipml;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.second.common.pojo.Teacher;
import com.second.teacher.dao.TeacherDao;
import com.second.teacher.service.TeacherService;
import com.second.teacher.vo.TeacherVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;

/**
 * @program: second-education-parent
 * @description:
 * @author: 王子朋
 * @create: 2023-05-26 18:57
 **/
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeacherDao teacherDao;

    @Override
    public Page<Teacher> findByConditionPage(Integer current, Integer pageSize, TeacherVo teacherVo) {
        Page<Teacher> page = new Page<>(current, pageSize);
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(teacherVo.getName())){
            wrapper.like("name",teacherVo.getName());
        }
        if (StringUtils.hasText(teacherVo.getMobile())){
            wrapper.like("mobile",teacherVo.getMobile());
        }
        if (StringUtils.hasText(teacherVo.getStatus())){
            wrapper.like("status",teacherVo.getStatus());
        }
        Page<Teacher> page1 = teacherDao.selectPage(page, wrapper);
        return page1;
    }

    @Override
    public int updateStatus(String id, String Status) {
        Teacher teacher = new Teacher();
        teacher.setId(id);
        teacher.setStatus(Status);
        teacher.setGmtModified(LocalDateTime.now());
        int row = teacherDao.updateById(teacher);
        return row;
    }

    @Override
    public Teacher findOneById(String id) {
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        return teacherDao.selectOne(wrapper);
    }

    @Override
    public void update(Teacher teacher) {
        teacherDao.updateById(teacher);
    }

    @Override
    public void updateById(Teacher teacher) {
        teacherDao.updateById(teacher);
    }
    @ApiOperation(value = "分页查询讲师审核表")
    @Override
    public Page<Teacher> findCheckTeacher(Integer current, Integer pageSize, TeacherVo teacherVo) {
        Page<Teacher> page = new Page<>(current, pageSize);
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(teacherVo.getName())){
            wrapper.like("name",teacherVo.getName());
        }
        if (StringUtils.hasText(teacherVo.getMobile())){
            wrapper.like("mobile",teacherVo.getMobile());
        }
        if (StringUtils.hasText(teacherVo.getStatus())){
            wrapper.like("status",teacherVo.getStatus());
        }
        Page<Teacher> checkTeacher = teacherDao.findCheckTeacher(page,wrapper);
        return checkTeacher;
    }

    @Override
    public int updateshenhe(Teacher teacher) {
        int updateshenhe = teacherDao.updateshenhe(teacher);
        return updateshenhe;
    }


}
